using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Newtonsoft.Json;  

public class MainMenuPanel : MonoBehaviour
{
    private Button startButton; 
    private Button settingsButton; 
    private Button progressButton; 
    private Button exitButton;
    private GameObject settingsPanel;

    private void Awake()
    {
        startButton = GameObject.Find("StartButton").GetComponent<Button>();
        settingsButton = GameObject.Find("SettingsButton").GetComponent<Button>();
        progressButton = GameObject.Find("ProgressButton").GetComponent<Button>();
        exitButton = GameObject.Find("ExitButton").GetComponent<Button>();
        settingsPanel = GameObject.Find("SettingsPanel");
        
        // 确保设置面板初始时是隐藏的
        if (settingsPanel != null)
        {
            settingsPanel.SetActive(false);
        }
    }

    // Start is called before the first frame update
    void Start()
    {
        startButton.onClick.AddListener(() =>
        {
            PlayMenuSound();
            SceneManager.LoadScene("02-LevelSelect");
        });
        
        settingsButton.onClick.AddListener(() =>
        {
            PlayMenuSound();
            if (settingsPanel != null)
            {
                settingsPanel.SetActive(true);
            }
        });
        
        progressButton.onClick.AddListener(() =>
        {
            PlayMenuSound();
            // 设置为无尽模式
            GameManager.Instance.isEndlessMode = true;
            SceneManager.LoadScene("02-LevelSelect");
        });

        exitButton.onClick.AddListener(() =>
        {
            PlayMenuSound();
            Application.Quit();
        });
    }

    private void PlayMenuSound()
    {
        var menuAudio = GameManager.Instance?.menuMusic?.GetComponent<AudioSource>();
        if (menuAudio != null)
        {
            menuAudio.enabled = true;
            menuAudio.Play();
        }
    }

    // Update is called once per frame
    void Update()
    {
        
    }
}
